package com.cw.util;

import java.awt.image.RGBImageFilter;

class ImageFilter extends RGBImageFilter {
	private int scansize;

	public ImageFilter(int scansize) {
		this.scansize = scansize;
		canFilterIndexColorModel = true;// false;
	}

	public int filterRGB(int x, int y, int rgb) {
		int ic = rgb & ~0xffffff;
		float r = (float) ((rgb & 0xff0000) >> 16);
		float g = (float) ((rgb & 0xff00) >> 8);
		float b = (float) (rgb & 0xff);
		r *= 0.2125F;
		g *= 0.7154F;
		b *= 0.0721F;
		int c = (int) Math.min(r + g + b + (float) this.scansize, 255.0F);
		return ic | c << 16 | c << 8 | c;
	}
}

class Transparency extends RGBImageFilter {
	// the color we are looking for... Alpha bits are set to opaque
	public int markerRGB = 0xFF000000;

	public Transparency(java.awt.Color color) {
		markerRGB = color.getRGB() | 0xFF000000;
	}

	public int filterRGB(int x, int y, int rgb) {
		if ((rgb | 0xFF000000) == markerRGB) {
			// Mark the alpha bits as zero - transparent
			return 0x00FFFFFF & rgb;
		} else {
			// nothing to do
			return rgb;
		}
	}
}